package com.clstu.socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketTCP02Server {
    public static void main(String[] args) throws IOException {

        ServerSocket serverSocket = new ServerSocket(9999);
        Socket socket = serverSocket.accept();//接受
        InputStream inputStream = socket.getInputStream();
        OutputStream outputStream = socket.getOutputStream();
        int readLen = 0;
        byte[] buf = new byte[1024];
        while ((readLen = inputStream.read(buf))!=-1){
            System.out.println(new String(buf,0,readLen));
        }
        outputStream.write("hello , client !".getBytes());
        socket.shutdownOutput();//设置结束语标记(表示自己说话已经说完了） 防止通信双方一直等待

        outputStream.close();
        inputStream.close();
        serverSocket.close();
        socket.close();
    }
}
